<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>获取元素-3</title>
</head>
<body>
    <div class="box">盒子</div>
    <div class="box">盒子</div>
    <div id="nav">
        <ul>
            <li>首页</li>
            <li>产品</li>
        </ul>
    </div>
    <script>
        // 1 根据类名选择元素  getElementsByClassName()
      var boxs = document.getElementsByClassName('box');
      console.log(boxs);

    //   2 querySelector() 返回指定选择器的第一个元素对象  切记 里面的选择器需要加符号 .box  #nav  标签的花直接写就行
    var firstBox = document.querySelector('.box');
    console.log(firstBox);

    var nav = document.querySelector('#nav');
    console.log(nav);

    var li = document.querySelector('li');
    console.log(li);

    // 3  querySelectorAll()  返回的是指定选择器的所有元素对象集合
        var allBox = document.querySelectorAll('.box');
        console.log(allBox);
    </script>
</body>
</html>